package main

import (
	"fmt"
)

var ch1 chan int
var ch2 chan int
var chs = []chan int{ch1, ch2}
var numbers = []int{1, 2, 3, 4, 5}

func main() {
	test2()
}

func test2() {
	ch1 := make(chan int, 1)
	ch2 := make(chan int, 1)
	ch1 <- 3
	ch2 <- 5
	select {
	case <-ch1:
		fmt.Println("ch1 selected.")
	case <-ch2:
		fmt.Println("ch2 selected.")
		fmt.Println("ch2 selected without break")
	}
}

func test1() {

	select {
	case getChan(0) <- getNumber(2):
		fmt.Println("1th case is selected.")
	case getChan(1) <- getNumber(3):
		fmt.Println("2th case is selected.")
	default:
		fmt.Println("default!.")

	}

}

func getNumber(i int) int {
	fmt.Printf("numbers[%d]\n", i)

	return numbers[i]
}

func getChan(i int) chan int {
	fmt.Printf("chs[%d]\n", i)
	return chs[i]

}
